#include "ACT/TurnTable/TurnTableRunningStateManager.h"

TurnTableRunningStateManager::TurnTableRunningStateManager(QObject* parent):QObject(parent)
{
	setObjectName(getClassNameFirstLow<TurnTableRunningStateManager>());
}

TurnTableRunningStateManager::~TurnTableRunningStateManager()
{
}
void TurnTableRunningStateManager::slot_recordTurnTableRunningState(TurnTableCodec::TurnTableInstructionFlag instructionFlag, float arg1, float arg2, float arg3)
{
	switch (instructionFlag)
	{
	case TurnTableCodec::TurnTable_SetLoad:
		switch ((int)arg1)
		{
		case TurnTableCodec::Mode_Loaded:
			state_turnTable_loadMode = TurnTableCodec::Mode_Loaded;
			break;
		case TurnTableCodec::Mode_Unloaded:
			state_turnTable_loadMode = TurnTableCodec::Mode_Unloaded;
			break;
		default:
			break;
		}
		break;
	case TurnTableCodec::TurnTable_SetPositionMode:
		state_turnTable_runningMode = TurnTableCodec::Mode_PositionMode;
		state_turnTable_targetPosition = arg1;
		state_turnTable_targetRate = arg2;
		state_turnTable_targetAcceleration = arg3;
		break;
	case TurnTableCodec::TurnTable_SetRateMode:
		state_turnTable_runningMode = TurnTableCodec::Mode_RateMode;
		state_turnTable_targetRate = arg1;
		state_turnTable_targetAcceleration = arg2;
		break;
	case TurnTableCodec::Thermostat_TargetTemperature:
		state_thermostat_targetTemperature = arg1;
		break;
	case TurnTableCodec::Thermostat_TemperatureRate:
		state_thermostat_temperatureRate = arg1;
		break;
	default:
		break;
	}
}
void TurnTableRunningStateManager::slot_setTurnTableCurrentState(float position, float rate)
{
	state_turnTable_currentPosition = position;
	state_turnTable_currentRate = rate;
}
void TurnTableRunningStateManager::slot_setTurnTableSearchZeroState(TurnTableCodec::TurnTableSearchZeroState turnTableSearchZeroState)
{
	state_turnTable_searchZeroState = turnTableSearchZeroState;
}

void TurnTableRunningStateManager::slot_setTurnTableTargetPositionState(TurnTableCodec::TargetState targetState)
{
	state_turnTable_isPositionReached = targetState;
}

void TurnTableRunningStateManager::slot_setTurnTableTargetRateState(TurnTableCodec::TargetState targetState)
{
	state_turnTable_isRateReached = targetState;
}

void TurnTableRunningStateManager::slot_setTurnTableTargetStopState(TurnTableCodec::TargetState targetState)
{
	state_turnTable_isStopReached = targetState;
}

void TurnTableRunningStateManager::slot_setTurnTablePowerSupplyState(TurnTableCodec::TurnTablePowerSupplyState turnTablePowerSupplyState)
{
	state_turnTable_powerSupplyState = turnTablePowerSupplyState;
}

void TurnTableRunningStateManager::slot_setTurnTableCircuitState(TurnTableCodec::TurnTableCircuitState turnTableCircuitState)
{
	state_turnTable_circuitState = turnTableCircuitState;
}

void TurnTableRunningStateManager::slot_setTurnTableAmplifierState(TurnTableCodec::TurnTableAmplifierState turnTableAmplifierState)
{
	state_turnTable_amplifierState = turnTableAmplifierState;
}

void TurnTableRunningStateManager::slot_setTurnTableRunningState(TurnTableCodec::TurnTableRunningState turnTableRunningState)
{
	state_turnTable_runningState = turnTableRunningState;
}

void TurnTableRunningStateManager::slot_setCurrentThermostatTemperature(float temperature)
{
	state_thermostat_currentTemperature = temperature;
}

TurnTableCodec::TurnTableLoadMode TurnTableRunningStateManager::getState_turnTable_loadMode()
{
	return state_turnTable_loadMode;
}
TurnTableCodec::TargetState TurnTableRunningStateManager::getState_turnTable_isPositionReached()
{
	return state_turnTable_isPositionReached;
}
TurnTableCodec::TargetState TurnTableRunningStateManager::getState_turnTable_isRateReached()
{
	return state_turnTable_isRateReached;
}
TurnTableCodec::TargetState TurnTableRunningStateManager::getState_turnTable_isStopReached()
{
	return state_turnTable_isStopReached;
}
TurnTableCodec::TurnTablePowerSupplyState TurnTableRunningStateManager::getState_turnTable_powerSupply()
{
	return state_turnTable_powerSupplyState;
}
TurnTableCodec::TurnTableCircuitState TurnTableRunningStateManager::getState_turnTable_circuit()
{
	return state_turnTable_circuitState;
}
TurnTableCodec::TurnTableAmplifierState TurnTableRunningStateManager::getState_turnTable_amplifier()
{
	return state_turnTable_amplifierState;
}
TurnTableCodec::TurnTableRunningState TurnTableRunningStateManager::getState_turnTable_running()
{
	return state_turnTable_runningState;
}
TurnTableCodec::TurnTableSearchZeroState TurnTableRunningStateManager::getState_turnTable_searchZero()
{
	return state_turnTable_searchZeroState;
}
TurnTableCodec::TurnTableRunningMode TurnTableRunningStateManager::getState_turnTable_runningMode()
{
	return state_turnTable_runningMode;
}
float TurnTableRunningStateManager::getState_turnTable_currentPosition()
{
	return state_turnTable_currentPosition;
}
float TurnTableRunningStateManager::getState_turnTable_currentRate()
{
	return state_turnTable_currentRate;
}
float TurnTableRunningStateManager::getState_turnTable_targetPosition()
{
	return state_turnTable_targetPosition;
}
float TurnTableRunningStateManager::getState_turnTable_targetRate()
{
	return state_turnTable_targetRate;
}
float TurnTableRunningStateManager::getState_turnTable_targetAcceleration()
{
	return state_turnTable_targetAcceleration;
}
float TurnTableRunningStateManager::getState_thermostat_currentTemperature()
{
	return state_thermostat_currentTemperature;
}
float TurnTableRunningStateManager::getState_thermostat_targetTemperature()
{
	return state_thermostat_targetTemperature;
}
float TurnTableRunningStateManager::getState_thermostat_temperatureRate()
{
	return state_thermostat_temperatureRate;
}
TurnTableCodec* TurnTableRunningStateManager::getTurnTableCodec()
{
	return turnTableCodec;
}
void TurnTableRunningStateManager::setTurnTableCodec(TurnTableCodec* turnTableCodec)
{
	if (Q_NULLPTR != this->turnTableCodec)
	{
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_instructionEcho, this, &TurnTableRunningStateManager::slot_recordTurnTableRunningState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableCurrentState, this, &TurnTableRunningStateManager::slot_setTurnTableCurrentState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableSearchZeroState, this, &TurnTableRunningStateManager::slot_setTurnTableSearchZeroState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableTargetPositionState, this, &TurnTableRunningStateManager::slot_setTurnTableTargetPositionState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableTargetRateState, this, &TurnTableRunningStateManager::slot_setTurnTableTargetRateState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableTargetStop, this, &TurnTableRunningStateManager::slot_setTurnTableTargetStopState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTablePowerState, this, &TurnTableRunningStateManager::slot_setTurnTablePowerSupplyState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableCircuitState, this, &TurnTableRunningStateManager::slot_setTurnTableCircuitState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableAmplifierState, this, &TurnTableRunningStateManager::slot_setTurnTableAmplifierState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_turnTableRunningState, this, &TurnTableRunningStateManager::slot_setTurnTableRunningState);
		disconnect(this->turnTableCodec, &TurnTableCodec::signal_currentThermostatTemperature, this, &TurnTableRunningStateManager::slot_setCurrentThermostatTemperature);
	}
	this->turnTableCodec = turnTableCodec;
	printInjection(this, turnTableCodec);
	connect(this->turnTableCodec, &TurnTableCodec::signal_instructionEcho, this, &TurnTableRunningStateManager::slot_recordTurnTableRunningState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableCurrentState, this, &TurnTableRunningStateManager::slot_setTurnTableCurrentState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableSearchZeroState, this, &TurnTableRunningStateManager::slot_setTurnTableSearchZeroState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableTargetPositionState, this, &TurnTableRunningStateManager::slot_setTurnTableTargetPositionState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableTargetRateState, this, &TurnTableRunningStateManager::slot_setTurnTableTargetRateState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableTargetStop, this, &TurnTableRunningStateManager::slot_setTurnTableTargetStopState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTablePowerState, this, &TurnTableRunningStateManager::slot_setTurnTablePowerSupplyState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableCircuitState, this, &TurnTableRunningStateManager::slot_setTurnTableCircuitState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableAmplifierState, this, &TurnTableRunningStateManager::slot_setTurnTableAmplifierState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_turnTableRunningState, this, &TurnTableRunningStateManager::slot_setTurnTableRunningState);
	connect(this->turnTableCodec, &TurnTableCodec::signal_currentThermostatTemperature, this, &TurnTableRunningStateManager::slot_setCurrentThermostatTemperature);
}

void TurnTableRunningStateManager::objectAutoInjection(QHash<QString, QObject*>* objMap)
{
	setTurnTableCodec(getObjFromMap<TurnTableCodec>(objMap));
}